// index.js
import {baseApi} from '../../../utils/util.js';
Page({
  data: {
    notice: '',
    totalSeconds: 10,
    disabled: true,
    checked: false
  },
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {
    var that = this;
    that.startCountdown(that);
    // wx.request({
    //   url:  baseApi() + '/app/getNotice',
    //   method: 'POST',
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded' // 关键请求头
    //   },
    //   data: {},
    //   success(res){
    //     console.log(JSON.stringify(res));
    //     that.setData({
    //       notice: res.data.data
    //     });
    //     that.startCountdown(that);
    //   }
    // })
  },
  onReady(){
    
  },
  startCountdown(that) {
    console.log(that.data.totalSeconds);
    const timer = setInterval(() => {
      var totalSeconds  = that.data.totalSeconds;
      if (totalSeconds <= 0) {
        that.setData({
          'disabled':false
        });
        clearInterval(timer);
        //this.setData({ countdown: '时间到!' });
        return;
      }
      console.log(totalSeconds );
      console.log(totalSeconds - 1);
      that.setData({
        totalSeconds: totalSeconds - 1
      });
    }, 1000);
    // 保存定时器ID以便清除
    that.setData({ timer });
  },
  onUnload() {
    // 页面卸载时清除定时器
    clearInterval(this.data.timer);
  },
  onCheckboxChange(e){
    var checkedValues =  e.detail.value;
    console.log('checkbox发生change事件，携带value值为：',checkedValues);

    console.log("--------");
    
    console.log(this.data.checked);
    if(checkedValues.includes('agree')){
      wx.navigateTo({
        url: '/pages/visitor/index',
      })
    }
  }
})
